package edu.tongji.libraryapp;

import java.util.ArrayList;

import edu.tongji.libraryapp.adapter.NotificationListAdapter;
import edu.tongji.libraryapp.adapter.RenewInformationListAdapter;
import edu.tongji.libraryapp.model.Notification;
import edu.tongji.libraryapp.model.RenewInformation;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;

public class NotificationCenterActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_notification_center);

		bindUserInteraction();
		initNotificationListView();
		initRenewListView();
	}

	private void bindUserInteraction() {
		TextView accountSettingTitleText = (TextView) findViewById(R.id.notoficationCenterTitleText);
		accountSettingTitleText.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent mainIntent = new Intent();
				mainIntent.setClass(NotificationCenterActivity.this,
						MainActivity.class);
				startActivity(mainIntent);
				overridePendingTransition(R.anim.slide_in_right,
						R.anim.slide_out_right);
			}
		});

		final ListView notificationListView = (ListView) findViewById(R.id.notificationListView);
		final ListView renewListView = (ListView) findViewById(R.id.renewListView);

		TextView notificationListText = (TextView) findViewById(R.id.notificationListText);
		notificationListText.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				notificationListView.setVisibility(View.VISIBLE);
				renewListView.setVisibility(View.GONE);
			}
		});

		TextView renewListText = (TextView) findViewById(R.id.renewListText);
		renewListText.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				renewListView.setVisibility(View.VISIBLE);
				notificationListView.setVisibility(View.GONE);
			}
		});
	}

	private void initNotificationListView() {
		ListView notificationListView = (ListView) findViewById(R.id.notificationListView);
		ArrayList<Notification> notificationList = new ArrayList<Notification>();
		for (int i = 0; i < 5; i++) {
			notificationList.add(new Notification());
		}
		NotificationListAdapter notificationListAdapter = new NotificationListAdapter(
				getApplicationContext(), this, notificationList);
		notificationListView.setAdapter(notificationListAdapter);
	}

	private void initRenewListView() {
		ListView renewListView = (ListView) findViewById(R.id.renewListView);
		ArrayList<RenewInformation> renewList = new ArrayList<RenewInformation>();
		for (int i = 0; i < 5; i++) {
			renewList.add(new RenewInformation());
		}
		RenewInformationListAdapter renewInformationListAdapter = new RenewInformationListAdapter(
				getApplicationContext(), this, renewList);
		renewListView.setAdapter(renewInformationListAdapter);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent mainIntent = new Intent();
			mainIntent.setClass(NotificationCenterActivity.this,
					MainActivity.class);
			startActivity(mainIntent);
			overridePendingTransition(R.anim.slide_in_right,
					R.anim.slide_out_right);
		}
		return true;
	}
}
